package com.sg.service.biz.bff.impl;

import cn.hutool.core.bean.BeanUtil;
import com.sg.common.dto.TreeNode;
import com.sg.common.exception.Assert;
import com.sg.common.util.CommonFunctionHelper;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.bff.common.BffEvaObjTargetCycleDto;
import com.sg.dto.biz.bff.common.BffSubTargetContentDto;
import com.sg.dto.biz.bff.req.BffQueryNetDiskEvaTreeListReqDto;
import com.sg.dto.biz.bff.req.BffQueryNetDiskTreeSubordinateListReqDto;
import com.sg.dto.biz.bff.res.BffQueryNetDiskEvaTreeListRespDto;
import com.sg.dto.biz.bff.res.BffQueryNetDiskTreeSubordinateListRespDto;
import com.sg.dto.integration.app.QueryNetDiskEvaTreeListComReqDto;
import com.sg.dto.integration.app.QueryNetDiskEvaTreeListComRespDto;
import com.sg.dto.integration.app.QueryNetDiskTreeSubordinateListComReqDto;
import com.sg.dto.integration.app.QueryNetDiskTreeSubordinateListComRespDto;
import com.sg.service.biz.bff.NetDiskTargetContentService;
import com.wicket.okrapp.integration.NetDiskTargetContentService;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class NetDiskTargetContentServiceImpl implements NetDiskTargetContentService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    com.sg.service.biz.app.NetDiskTargetContentService fwAppNetDiskTargetContentClient;

    /**
     * B3查询网盘评价树列表(管理)[8839]
     * gen by moon at 3/28/2024, 2:13:07 PM
     */
    @Trace(operationName = "B3查询网盘评价树列表(管理)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryNetDiskEvaTreeListRespDto queryNetDiskEvaTreeList(BffQueryNetDiskEvaTreeListReqDto reqDto) {


        QueryNetDiskEvaTreeListComRespDto queryNetDiskEvaTreeListComRespDto_1 = null;
//步骤0: D3查询网盘评价树列表(公共) - queryNetDiskEvaTreeListCom
        QueryNetDiskEvaTreeListComRespDto queryNetDiskEvaTreeListComRespDto = null;
        QueryNetDiskEvaTreeListComReqDto queryNetDiskEvaTreeListComReqDto = new QueryNetDiskEvaTreeListComReqDto();
        queryNetDiskEvaTreeListComReqDto.setIsParentCycle("TRUE");//sourceId:1661120_1
        queryNetDiskEvaTreeListComReqDto.setSubjectLifeCycle("CURRENTLY_VALID");//sourceId:1661121_1
        if (reqDto != null) {
            queryNetDiskEvaTreeListComReqDto.setEvaObjTypeCode(reqDto.getEvaObjTypeCode());//SimpleFieldAssign//sourceId:1661119_1
            queryNetDiskEvaTreeListComReqDto.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:1661122_1
        }

        /*D3查询网盘评价树列表(公共)[8838]   */
        Assert.isNull(queryNetDiskEvaTreeListComReqDto.getEvaObjTypeCode(), "B3查询网盘评价树列表(管理)-D3查询网盘评价树列表(公共)-被评对象类型编码不能为空", false);
        Assert.isNull(queryNetDiskEvaTreeListComReqDto.getEvaluationTemplateId(), "B3查询网盘评价树列表(管理)-D3查询网盘评价树列表(公共)-冗余评价模板ID不能为空", false);
        Assert.isNull(queryNetDiskEvaTreeListComReqDto.getIsParentCycle(), "B3查询网盘评价树列表(管理)-D3查询网盘评价树列表(公共)-是否父周期不能为空", false);
        Assert.isNull(queryNetDiskEvaTreeListComReqDto.getSubjectLifeCycle(), "B3查询网盘评价树列表(管理)-D3查询网盘评价树列表(公共)-主体生命周期不能为空", false);
        queryNetDiskEvaTreeListComRespDto = fwAppNetDiskTargetContentClient.queryNetDiskEvaTreeListCom(queryNetDiskEvaTreeListComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


        queryNetDiskEvaTreeListComRespDto_1 = queryNetDiskEvaTreeListComRespDto;

        BffQueryNetDiskEvaTreeListRespDto retData = new BffQueryNetDiskEvaTreeListRespDto();
        if (queryNetDiskEvaTreeListComRespDto_1 != null) {
            retData.setEvaObjTargetCycleList(queryNetDiskEvaTreeListComRespDto_1.getEvaObjTargetCycleList().stream().map(item -> BeanUtil.toBean(item, BffEvaObjTargetCycleDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:1661136_1
        }


        List<Object> allNodes = new ArrayList<>();
        allNodes.addAll(retData.getEvaObjTargetCycleList());
        List<TreeNode> nodeList = CommonFunctionHelper.buildTree(allNodes);
        retData.setTreeNode(nodeList);
        retData.setEvaObjTargetCycleList(null);

        return retData;
    }

    /**
     * B3查询网盘树节点下级列表(管理)[8840]
     * gen by moon at 5/11/2024, 11:58:09 PM
     */
    @Trace(operationName = "B3查询网盘树节点下级列表(管理)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryNetDiskTreeSubordinateListRespDto queryNetDiskTreeSubordinateList(BffQueryNetDiskTreeSubordinateListReqDto reqDto) {


        QueryNetDiskTreeSubordinateListComRespDto queryNetDiskTreeSubordinateListComRespDto_1 = null;
//步骤0: D3查询网盘树节点下级内容列表(公共) - queryNetDiskTreeSubordinateListCom
        QueryNetDiskTreeSubordinateListComRespDto queryNetDiskTreeSubordinateListComRespDto = null;
        QueryNetDiskTreeSubordinateListComReqDto queryNetDiskTreeSubordinateListComReqDto = new QueryNetDiskTreeSubordinateListComReqDto();
        if (reqDto != null) {
            queryNetDiskTreeSubordinateListComReqDto.setEvaObjTypeCode(reqDto.getEvaObjTypeCode());//SimpleFieldAssign//sourceId:1661521_1
            queryNetDiskTreeSubordinateListComReqDto.setParentEvaObjTargetCycleId(reqDto.getParentEvaObjTargetCycleId());//SimpleFieldAssign//sourceId:1661461_1
            queryNetDiskTreeSubordinateListComReqDto.setTargetCycleContentTypeCode(reqDto.getTargetCycleContentTypeCode());//SimpleFieldAssign//sourceId:1661460_1
            queryNetDiskTreeSubordinateListComReqDto.setIsLastTargetContent(reqDto.getIsLastTargetContent());//SimpleFieldAssign//sourceId:1661463_1
            queryNetDiskTreeSubordinateListComReqDto.setEvaluationTemplateId(reqDto.getEvaluationTemplateId());//SimpleFieldAssign//sourceId:1661462_1
        }

        /*D3查询网盘树节点下级内容列表(公共)[8837]   */
        Assert.isNull(queryNetDiskTreeSubordinateListComReqDto.getEvaObjTypeCode(), "B3查询网盘树节点下级列表(管理)-D3查询网盘树节点下级内容列表(公共)-被评对象类型编码不能为空", false);
        Assert.isNull(queryNetDiskTreeSubordinateListComReqDto.getParentEvaObjTargetCycleId(), "B3查询网盘树节点下级列表(管理)-D3查询网盘树节点下级内容列表(公共)-上级被评对象目标周期标识不能为空", false);
        Assert.isNull(queryNetDiskTreeSubordinateListComReqDto.getTargetCycleContentTypeCode(), "B3查询网盘树节点下级列表(管理)-D3查询网盘树节点下级内容列表(公共)-上级目标内容类型编码不能为空", false);
        Assert.isNull(queryNetDiskTreeSubordinateListComReqDto.getIsLastTargetContent(), "B3查询网盘树节点下级列表(管理)-D3查询网盘树节点下级内容列表(公共)-上级是否末级目标内容不能为空", false);
        Assert.isNull(queryNetDiskTreeSubordinateListComReqDto.getEvaluationTemplateId(), "B3查询网盘树节点下级列表(管理)-D3查询网盘树节点下级内容列表(公共)-冗余评价模板ID不能为空", false);
        queryNetDiskTreeSubordinateListComRespDto = fwAppNetDiskTargetContentClient.queryNetDiskTreeSubordinateListCom(queryNetDiskTreeSubordinateListComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


        queryNetDiskTreeSubordinateListComRespDto_1 = queryNetDiskTreeSubordinateListComRespDto;

        BffQueryNetDiskTreeSubordinateListRespDto retData = new BffQueryNetDiskTreeSubordinateListRespDto();
        if (queryNetDiskTreeSubordinateListComRespDto_1 != null) {
            retData.setSubTargetContentList(queryNetDiskTreeSubordinateListComRespDto_1.getSubTargetContentList().stream().map(item -> BeanUtil.toBean(item, BffSubTargetContentDto.class)).collect(Collectors.toList()));//objList-to-objLists//sourceId:1661469_1
        }


        return retData;
    }
    //
}
